package com.hansen.library.ui.widget.pop;

import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.widget.PopupWindow;

import com.hansen.library.utils.ScreenSizeUtils;

/**
 * @author han
 * @date 2019/9/20
 */
public class YNPopupWindow extends PopupWindow {

    public YNPopupWindow(View mMenuView, int width, int height) {
        this(mMenuView, width, height, false);
    }

    public YNPopupWindow(View mMenuView, int width, int height, boolean focusable) {
        super(mMenuView, width, height, focusable);
    }

    @Override
    public void showAsDropDown(View anchor) {
        showAsDropDown(anchor, 0, 0);
    }

    @Override
    public void showAsDropDown(View anchor, int xoff, int yoff) {
        if (Build.VERSION.SDK_INT >= 24) {
            Rect rect = new Rect();
            anchor.getLocalVisibleRect(rect);
            int h = ScreenSizeUtils.getRealHeight(getContentView().getContext()) - rect.bottom - yoff;
            setHeight(h);
        }
        super.showAsDropDown(anchor, xoff, yoff);
    }
}
